package BankingManagement;/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */

/**
 *
 * @author ashongtical
 */

public class BankAccount {
    private double balance;          // Account balance
    private int depositsCount;       // Number of deposits this month
    private int withdrawalsCount;    // Number of withdrawals this month
    private double annualInterestRate; // Annual interest rate
    private double monthlyServiceCharges; // Monthly service charges
    private static final double MINIMUM_BALANCE = 25.0; // Minimum required balance

    // Constructor to initialize account with balance and annual interest rate
    public BankAccount(double balance, double annualInterestRate) {
        this.balance = balance;
        this.annualInterestRate = annualInterestRate;
        this.depositsCount = 0;
        this.withdrawalsCount = 0;
        this.monthlyServiceCharges = 0;
    }

    // Method to deposit money into account
    public void deposit(double amount) {
        if (amount <= 0) {
            System.out.println("Deposit amount must be greater than 0");
            return;
        }
        balance += amount;
        depositsCount++;
        System.out.println("Deposit successful: RMB " + amount);
    }

    // Method to withdraw money from account
    public void withdraw(double amount) {
        if (amount <= 0) {
            System.out.println("Withdrawal amount must be greater than 0");
            return;
        }

        if (balance - amount < MINIMUM_BALANCE) {
            System.out.println("Withdrawal failed: Insufficient balance. Minimum balance must be RMB " + MINIMUM_BALANCE);
            return;
        }

        balance -= amount;
        withdrawalsCount++;
        System.out.println("Withdrawal successful: RMB " + amount);
    }

    // Method to calculate monthly interest
    public void calcInterest() {
        double monthlyInterestRate = annualInterestRate / 12 / 100;
        double interest = balance * monthlyInterestRate;
        balance += interest;
        System.out.println("Interest calculated: RMB " + interest);
    }

    // Method to perform monthly processing
    public void monthlyProcess() {
        balance -= monthlyServiceCharges;
        calcInterest();
        depositsCount = 0;
        withdrawalsCount = 0;
        monthlyServiceCharges = 0;
        System.out.println("Monthly processing completed. Current balance: RMB " + balance);
    }

    // Method to display account details
    public void displayAccountDetails() {
        System.out.println("\nAccount Details:");
        System.out.println("Current Balance: RMB " + balance);
        System.out.println("Deposits this month: " + depositsCount);
        System.out.println("Withdrawals this month: " + withdrawalsCount);
        System.out.println("Annual Interest Rate: " + annualInterestRate + "%");
        System.out.println("Monthly Service Charges: RMB " + monthlyServiceCharges);
    }

    // Getter methods
    public double getBalance() {
        return balance;
    }

    public int getDepositsCount() {
        return depositsCount;
    }

    public int getWithdrawalsCount() {
        return withdrawalsCount;
    }

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public double getMonthlyServiceCharges() {
        return monthlyServiceCharges;
    }

    // Setter for monthlyServiceCharges
    public void setMonthlyServiceCharges(double charges) {
        this.monthlyServiceCharges = charges;
    }
}
